import socket
from util.OS.platformConfig import GetUser

import wmi


def main():
    w = wmi.WMI()
    strs = ''
    # 获取电脑使用者信息
    for CS in w.Win32_ComputerSystem():
        strs += '-------------------------ComputerSystem-------------------------' + '\n'
        strs += "电脑名称: %s" % CS.Caption + '\n'
        strs += "使用者: %s" % CS.UserName + '\n'
        strs += "制造商: %s" % CS.Manufacturer + '\n'
        strs += "系统信息: %s" % CS.SystemFamily + '\n'
        strs += "工作组: %s" % CS.Workgroup + '\n'
        strs += "机器型号: %s" % CS.model + '\n'
    # 获取操作系统信息
    for OS in w.Win32_OperatingSystem():
        strs += '-------------------------OperatingSystem-------------------------' + '\n'
        # strs += OS + '\n'
        strs += "操作系统: %s" % OS.Caption + '\n'
        strs += "语言版本: %s" % OS.MUILanguages + '\n'
        strs += "系统位数: %s" % OS.OSArchitecture + '\n'
        strs += "注册人: %s" % OS.RegisteredUser + '\n'
        strs += "系统驱动: %s" % OS.SystemDevice + '\n'
        strs += "系统目录: %s" % OS.SystemDirectory + '\n'
    # 获取电脑IP和MAC信息
    for address in w.Win32_NetworkAdapterConfiguration(ServiceName="e1dexpress"):
        strs += '-------------------NetworkAdapterConfiguration-------------------' + '\n'
        # strs += address + '\n'
        strs += "IP地址: %s" % address.IPAddress + '\n'
        strs += "MAC地址: %s" % address.MACAddress + '\n'
        strs += "网络描述: %s" % address.Description + '\n'
    # 获取电脑CPU信息
    for processor in w.Win32_Processor():
        strs += "----------------------------Processor----------------------------" + '\n'
        # strs += processor + '\n'
        strs += "CPU型号: %s" % processor.Name.strip() + '\n'
        strs += "CPU核数: %s" % processor.NumberOfCores + '\n'
    # 获取BIOS信息
    for BIOS in w.Win32_BIOS():
        strs += "-------------------------------BIOS-------------------------------" + '\n'
        # strs += BIOS + '\n'
        strs += "使用日期: %s" % BIOS.Description + '\n'
        strs += "主板型号: %s" % BIOS.SerialNumber + '\n'
        strs += "当前语言: %s" % BIOS.CurrentLanguage + '\n'
    # 获取内存信息
    for memModule in w.Win32_PhysicalMemory():
        strs += "--------------------------PhysicalMemory--------------------------" + '\n'
        totalMemSize = int(memModule.Capacity)
        strs += "内存厂商: %s" % memModule.Manufacturer + '\n'
        strs += "内存型号: %s" % memModule.PartNumber + '\n'
        strs += "内存大小: %.2fGB" % (totalMemSize / 1024 ** 3) + '\n'
    # 获取磁盘信息
    for disk in w.Win32_DiskDrive():
        strs += "-----------------------------DiskDrive----------------------------" + '\n'
        diskSize = int(disk.size)
        strs += "磁盘名称: %s" % disk.Caption + '\n'
        strs += "硬盘型号: %s" % disk.Model + '\n'
        strs += "磁盘大小: %.2fGB" % (diskSize / 1024 ** 3) + '\n'
    # 获取显卡信息
    for xk in w.Win32_VideoController():
        strs += '--------------------------VideoController-------------------------' + '\n'
        strs += "显卡名称: %s" % xk.name + '\n'
    # 获取计算机名称和IP
    strs += "---------------------------ComputerName---------------------------" + '\n'
    hostname = socket.gethostname()
    ip = socket.gethostbyname(hostname)
    strs += "计算机名称: %s" % hostname + '\n'
    strs += "IP地址: %s" % ip + '\n'
    strs += "-----------------------------UserName------------------------------" + \
            '\nUser:: '
    strs += '\nUser:: '.join(GetUser.main())
    return strs


if __name__ == '__main__':
    main()
